package handle

import (
	"context"
	pb "week2zk-project/rpc/api/goods"
	"week2zk-project/rpc/internal/model"
)

func (s *GoodsInfoService) GetGoodsByTitle(ctx context.Context, req *pb.GetGoodsByTitleRequest) (*pb.GetGoodsByTitleResponse, error) {
	g := model.Goods{
		GoodsTitle: req.GoodsTitle,
	}
	err := g.Details(g.GoodsTitle)
	if err != nil {
		return &pb.GetGoodsByTitleResponse{}, err
	}
	return &pb.GetGoodsByTitleResponse{
		GoodsTitle:  g.GoodsTitle,
		GoodsImg:    g.GoodsImg,
		GoodsPrice:  g.GoodsPrice,
		GoodsStock:  g.GoodsStock,
		SalesVolume: g.SalesVolume,
		Evaluate:    g.Evaluate,
	}, nil
}
